/*
 * @Author: “ygnnli” “1585923072@qq.com”
 * @Date: 2024-08-04 22:07:36
 * @LastEditors: “ygnnli” “1585923072@qq.com”
 * @LastEditTime: 2024-08-04 22:29:10
 * @FilePath: /110/54/test/test.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include <jsoncpp/json/json.h>
#include <iostream>
#include <string>
#include <fstream>

struct stu
{
    std::string name;
    int age;
    double weight;

public:
    void debug()
    {
        std::cout << name << std::endl;
        std::cout << age << std::endl;
        std::cout << weight << std::endl;
    }
};

int main()
{

    std::ifstream in("out.txt");
    if (!in.is_open())
        return 1;
    char buffer[1024];
    in.read(buffer, sizeof(buffer));
    in.close();

    std::string json_string = buffer;
    Json::Value root;
    Json::Reader reader;
    bool res = reader.parse(json_string, root);
    (void)res;

    struct stu zs;
    zs.name = root["name"].asString();
    zs.age = root["age"].asInt();
    zs.weight = root["weight"].asDouble();

    zs.debug();

    // // 结构化数据
    // struct stu zs = {"历史书", 18, 70};

    // // 转换成为字符串
    // Json::Value root;
    // root["name"] = zs.name;
    // root["age"] = zs.age;
    // root["weight"] = zs.weight;
    // // root["self"] = root;

    // // Json::FastWriter writer; // 序列化
    // Json::StyledWriter writer;
    // std::string str = writer.write(root);

    // std::ofstream out("out.txt");
    // if (!out.is_open())
    // {
    //     std::cout << str;
    //     return 1;
    // }
    // out << str;

    // out.close();

    return 0;
}